import 'dart:convert';

import 'package:base_flutter/base_flutter.dart';
import 'package:ls_work/net/response/work_menu_data.dart';

class UserPermissionData {
  ///照护记录单
  static const String careRecord = "APP.MYJOB.CARERECORD";

  ///体征登记
  static const String healthSign = "APP.MYJOB.HEALTHREG";

  ///活动登记
  static const String activitySign = "APP.MYJOB.ACTIVITY";

  ///请假登记
  static const String leaveSign = "APP.MYJOB.LEAVEREG";

  ///就医登记
  static const String medicalSign = "APP.MYJOB.MEDICALREG";

  ///饮食登记
  static const String mealSign = "APP.MYJOB.MEALSIGN";

  ///交接班
  static const String handOver = "APP.MYJOB.CHANGESHIFTS";

  ///健康检测
  static const String healthCheck = "APP.MYJOB.HEALTHMONITORING";

  ///服务响应
  static const String serviceOrder = "APP.MYJOB.SERVICERESP";

  ///安全巡防
  static const String safePatrol = "APP.MYJOB.SAFETYPATROL";

  ///设备维保
  static const String equipmentRepair = "APP.MYJOB.EQUIPMENTMAINTENANCE";

  ///照护实施
  static const String nurseCare = "APP.MYJOB.CAREIMPLEMENTATION";

  ///照护实施(新)
  static const String nurseCareNew = "APP.MYJOB.CAREIMPLEMENTATIONNEW";

  ///点餐
  static const String orderMeal = "APP.MYJOB.ORDERMEAL";

  ///访客核销
  static const String visitorCheck = "APP.MYJOB.VISITORVERIFY";

  ///访客审核
  static const String visitorAudit = "APP.MYJOB.VISITORAudit";

  ///报警提醒
  static const String warningNotice = "APP.MYJOB.ALARMREMINDER";

  ///服务派单
  static const String sendServiceOrder = "APP.MYJOB.SERVICEDISPATCH";

  ///食品留样
  static const String foodSample = "APP.MYJOB.FOODSAMPLE";

  ///抄表
  static const String meterReading = "APP.MYJOB.METERREADING";

  ///服务单
  static const String simpleServiceOrder = "APP.MYJOB.SERVICEORDER";

  ///智能设备
  static const String smartEquipment = "APP.MYJOB.SMARTEQUIPMENT";

  ///排班信息
  static const String schedulingPlan = "APP.MYJOB.SCHEDULINGPLAN";

  ///活动报名
  static const String signInActivity = "APP.MYJOB.SIGNINACTIVITY";

  ///审批
  static const String approval = "APP.MYJOB.APPROVE";

  ///领用申请
  static const String useRequest = "APP.MYJOB.USEREQUEST";

  ///通讯录
  static const String addressBook = "APP.MYJOB.ADDRESSBOOK";

  ///事件管理
  static const String eventManage = "APP.MYJOB.EVENTMANAGE";

  ///医嘱记录
  static const String medicalAdvice = "APP.MYJOB.MEDICALADVICE";

  ///治疗单
  static const String treatmentSheet = "APP.MYJOB.TREATMENTSHEET";

  ///缺药清单
  static const String medicineLack = "APP.MYJOB.MEDICINELACKLIST";

  ///收药入柜
  static const String receiveMedicine = "APP.MYJOB.RECEIVEMEDICINE";

  ///药品移交
  static const String medicineHandover = "APP.MYJOB.MEDICINEHANDOVER";

  ///摆药
  static const String putMedicine = "APP.MYJOB.PUTMEDICINE";

  ///服药
  static const String takeMedicine = "APP.MYJOB.TAKEMEDICINE";

  ///进出记录
  static const String entryRecord = "APP.MYJOB.ENTRYRECORD";

  ///医嘱核对
  static const String medicineAdviceCheck = "APP.MYJOB.MEDICINEADVICECHECK";

  ///不良事件
  static const String badEvent = "APP.MYJOB.BADEVENT";

  ///健康预警
  static const String abnormalEvent = "APP.MYJOB.ABNORMALEVENT";

  ///运营数据
  static const String operationalStatistics = "APP.MYJOB.OPERATIONALSTATISTICS";

  ///应急事件
  static const String emergencyEvent = "APP.MYJOB.EMERGENCYEVENT";

  ///巡诊记录
  static const String doctorPatrol = "APP.MYJOB.DOCTORPATROL";

  ///药库查询
  static const String medicineLibrarySearch = "APP.MYJOB.MEDICINELIBRARYSEARCH";

  ///医嘱录入
  static const String doctorAdviceSign = "APP.MYJOB.DOCTORADVICESIGN";

  static List<Map<String, dynamic>> get menus => [
        {
          "title": "我的工作",
          "subMenus": [
            {"title": "体征登记", "moduleName": healthSign},
            {"title": "请假登记", "moduleName": leaveSign},
            {"title": "就医登记", "moduleName": medicalSign},
            {"title": "交接班", "moduleName": handOver},
            {"title": "健康检测", "moduleName": healthCheck},
            {"title": "服务响应", "moduleName": serviceOrder},
            {"title": "安全巡防", "moduleName": safePatrol},
            {"title": "设备维保", "moduleName": equipmentRepair},
            {"title": "照护实施", "moduleName": nurseCare},
            {"title": "照护实施(新)", "moduleName": nurseCareNew},
            {"title": "点餐", "moduleName": orderMeal},
            {"title": "访客核销", "moduleName": visitorCheck},
            {"title": "报警提醒", "moduleName": warningNotice},
            {"title": "服务派单", "moduleName": sendServiceOrder},
            {"title": "食品留样", "moduleName": foodSample},
            {"title": "抄表", "moduleName": meterReading},
            {"title": "服务单", "moduleName": simpleServiceOrder},
            // {"title": "智能设备", "moduleName": smartEquipment},
            // {"title": "排班管理", "moduleName": schedulingPlan},
            {"title": "活动内容", "moduleName": signInActivity},
            {"title": "审批", "moduleName": approval},
            {"title": "领用申请", "moduleName": useRequest},
            // {"title": "通讯录", "moduleName": addressBook},
            // {"title": "事件管理", "moduleName": eventManage},
            // {"title": "医嘱记录", "moduleName": medicalAdvice},
            // {"title": "治疗单", "moduleName": treatmentSheet},
            // {"title": "缺药清单", "moduleName": medicineLack},
            // {"title": "收药入柜", "moduleName": receiveMedicine},
            // {"title": "药品移交", "moduleName": medicineHandover},
            {"title": "摆药", "moduleName": putMedicine},
            {"title": "服药", "moduleName": takeMedicine},
            {"title": "出入记录", "moduleName": entryRecord},
            {"title": "医嘱核对", "moduleName": medicineAdviceCheck},
            {"title": "不良事件", "moduleName": badEvent},
            {"title": "健康预警", "moduleName": abnormalEvent},
            {"title": "运营统计", "moduleName": operationalStatistics},
            {"title": "应急事件", "moduleName": emergencyEvent},
            {"title": "巡诊记录", "moduleName": doctorPatrol},
            {"title": "药库查询", "moduleName": medicineLibrarySearch},
            {"title": "医嘱录入", "moduleName": doctorAdviceSign},
          ]
        }
      ];

  static List<WorkMenuData> menuList = [];

  Future<void> init() async {
    var json = await getString("menuStr");
    if (json.isNullOrEmpty() || BuildConfig.isDebug) {
      menuList = menus.map((e) => WorkMenuData.fromJson(e)).toList();
    } else {
      var listMap = (jsonDecode(json!) as List)
          .map((e) => WorkMenuData.fromJson(e))
          .toList();
      menuList = listMap;
    }
  }

  static Future<void> saveMenus(List items) async {
    if (items != null && items.isNotEmpty) {
      var json = jsonEncode(items);
      await saveValue('menuStr', json);
      menuList = items.map((e) => WorkMenuData.fromJson(e)).toList();
    } else {
      menuList = menus.map((e) => WorkMenuData.fromJson(e)).toList();
    }
  }

  static Future<void> clear() async {
    menuList = [];
    await saveValue("menuStr", "");
  }

  static String getFunImage(String moduleName) {
    switch (moduleName) {
      case leaveSign:
        return "home/icon_home_crxx";
      case careRecord:
        return "home/icon_home_hlxx";
      case healthSign:
        return "home/icon_home_jkxx";
      case activitySign:
        return "home/icon_home_hdxx";
      case mealSign:
        return "home/icon_home_ysxx";
      case medicalSign:
        return "home/icon_home_jyxx";
      case handOver:
        return "home/hand_over";
      case healthCheck:
        return "home/tag_17";
      case serviceOrder:
        return "home/fwd";
      case safePatrol:
        return "home/abxf";
      case equipmentRepair:
        return "home/sbwh";
      case nurseCare:
      case nurseCareNew:
        return "home/fwzx";
      case orderMeal:
        return "home/diancan";
      case visitorCheck:
        return "home/fkhx";
      case warningNotice:
        return "home/sos_warning";
      case sendServiceOrder:
        return "home/icon_fwpd";
      case foodSample:
        return "home/icon_sply";
      case meterReading:
        return "home/sdcb";
      case simpleServiceOrder:
        return "home/icon_fwd";
      case smartEquipment:
        return "zhsbgl";
      case schedulingPlan:
        return "home/pbxx";
      case signInActivity:
        return "home/hdnr";
      case approval:
        return "home/shenpi";
      case useRequest:
        return "home/lysq";
      case addressBook:
        return "home/tag_5";
      case eventManage:
        return "home/tag_6";
      case medicalAdvice:
        return "home/yzjl";
      case treatmentSheet:
        return "home/zld";
      case medicineLack:
        return "home/qyqd";
      case receiveMedicine:
        return "home/syrg";
      case medicineHandover:
        return "home/ypyj";
      case putMedicine:
        return "home/baiyao";
      case takeMedicine:
        return "home/fuyao";
      case entryRecord:
        return "home/in_out_record";
      case medicineAdviceCheck:
        return "home/yzhd";
      case badEvent:
        return "home/blsj";
      case operationalStatistics:
        return "home/icon_yysj";
      case emergencyEvent:
        return "home/icon_yjsj";
      case doctorPatrol:
        return "home/icon_xzjl";
      case medicineLibrarySearch:
        return "home/icon_ykcx";
      case doctorAdviceSign:
        return "home/icon_yzlr";
      case abnormalEvent:
        return "home/icon_jkyj";

      default:
        return "";
    }
  }
}
